//
//  HLUIMacro.h
//  s.
//
//  Created by fanshijian on 2022/8/22.
//  Copyright © 2022 J. All rights reserved.
//

#import "JYDevice.h"

#ifndef HLUIMacro_h
#define HLUIMacro_h

#define KLWKSelf __weak typeof(self) wkSelf = (self);
#define KLSTSelf __strong typeof(wkSelf)self = (wkSelf);
#define weakObj(_obj_) __weak typeof((_obj_)) wk_##_obj_ = (_obj_);

//#pragma mark - 设备相关
//#define IS_Phone          (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
//#define IS_Pad            (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
////iPhone刘海屏
//#define IS_IPhoneX         ([JYDevice is_iPhoneX])
////iPad全面屏
//#define IS_FULLSCREEN_PAD  ([JYDevice is_FullScreenIpad])

///Masonry
#define kMakeL(v) make.left.equalTo((v))
#define kMakeLV(v) make.left.equalTo(@(v))
#define kMakeT(v) make.top.equalTo((v))
#define kMakeTV(v) make.top.equalTo(@(v))
#define kMakeB(v) make.bottom.equalTo((v))
#define kMakeBV(v) make.bottom.equalTo(@(v))
#define kMakeR(v) make.right.equalTo((v))
#define kMakeRV(v) make.right.equalTo(@(v))

#define kMakeW(v) make.width.equalTo((v))
#define kMakeWV(v) make.width.equalTo(@(v))
#define kMakeH(v) make.height.equalTo((v))
#define kMakeHV(v) make.height.equalTo(@(v))
        
#define kMakeLT(v) make.top.left.equalTo((v))
#define kMakeLTV(v) make.top.left.equalTo(@(v))
#define kMakeTR(v) make.top.right.equalTo((v))
#define kMakeTRV(v) make.top.right.equalTo(@(v))
#define kMakeLR(v) make.left.right.equalTo((v))
#define kMakeLRV(v) make.left.right.equalTo(@(v))
#define kMakeTB(v) make.top.bottom.equalTo((v))
#define kMakeTBV(v) make.top.bottom.equalTo(@(v))
#define kMakeLB(v) make.left.bottom.equalTo((v))
#define kMakeLBV(v) make.left.bottom.equalTo(@(v))
#define kMakeRB(v) make.right.bottom.equalTo((v))
#define kMakeRBV(v) make.right.bottom.equalTo(@(v))
        
#define kMakeLTR(v) make.top.left.right.equalTo((v))
#define kMakeLTRV(v) make.top.left.right.equalTo(@(v))
#define kMakeLTB(v) make.top.left.bottom.equalTo((v))
#define kMakeLTBV(v) make.top.left.bottom.equalTo(@(v))
#define kMakeTRB(v) make.top.right.bottom.equalTo((v))
#define kMakeTRBV(v) make.top.right.bottom.equalTo(@(v))
#define kMakeLBR(v) make.left.bottom.right.equalTo((v))
#define kMakeLBRV(v) make.left.bottom.right.equalTo(@(v))
#define kMakeEdge(v) make.edges.equalTo((v))
#define kMakeEdgeV(v) make.edges.insets((v))
#define kMakeEdge0 make.edges.insets(UIEdgeInsetsZero)

#define kMakeCenter(v) make.center.equalTo((v))
#define kMakeCenterX(v) make.centerX.equalTo((v))
#define kMakeCenterXV(v) make.centerX.equalTo(@(v))
#define kMakeCenterY(v) make.centerY.equalTo((v))
#define kMakeCenterYV(v) make.centerY.equalTo(@(v))

#define kMakeW(v) make.width.equalTo((v))
#define kMakeWV(v) make.width.equalTo(@(v))
#define kMakeH(v) make.height.equalTo((v))
#define kMakeHV(v) make.height.equalTo(@(v))
#define kMakeWH(v1, v2) make.width.equalTo((v1));\
make.height.equalTo((v2))
#define kMakeWHV(v1, v2) make.width.equalTo(@(v1));\
make.height.equalTo(@(v2))

#define kMakeS(v) make.size.equalTo(v)
#define kMakeSV(v) make.size.equalTo(@(v))

#define kEdge(T,L,B,R) UIEdgeInsetsMake((T), (L), (B), (R))
#define kSafeEdge (kEdge(kSafeLayout_NaviH, 0, kSafeLayout_B, 0))
#define kSize(w,h) CGSizeMake((w), (h))
#define kRect(X,Y,W,H) (CGRect){(X),(Y),(W),(H)}

#define klSafeAreaEdgeInsets \
({UIEdgeInsets safeEdgeInsets = UIEdgeInsetsZero;\
if (@available(iOS 11.0, *)) {\
safeEdgeInsets = [[UIApplication sharedApplication] delegate].window.safeAreaInsets;\
}\
(safeEdgeInsets);})

#define klStatusBarHeight (\
{CGFloat h = klSafeAreaEdgeInsets.top == 0?(klSafeAreaEdgeInsets.top+20):klSafeAreaEdgeInsets.top;\
(h);})

#define kSafeLayout_NaviH (IS_IPhoneX ? (88) : 64)

#define kl_Width(R) (R)*(kScreenWidth)/375.f
#define kl_Height(R) (R)*(kScreenHeight)/812.f


#import "JYColors.h"


#endif /* HLUIMacro_h */

///状态栏（电池栏）高度
static inline CGFloat JYStatusBarHeight() {
    if (@available(iOS 13.0, *)) {
        return [[[UIApplication sharedApplication] delegate] window].windowScene.statusBarManager.statusBarFrame.size.height;
    } else {
        return [[UIApplication sharedApplication] statusBarFrame].size.height;
    }
}
///navigationbar的高度（包含状态栏高度）
static inline CGFloat JYNavigationBarHeight() {
    return JYStatusBarHeight() + 44;
}

///底部安全区域
static inline CGFloat JYSafeAreaBottomMargin() {
    return klSafeAreaEdgeInsets.bottom;
}
///tabbar高度（包括底部安全区域）
static inline CGFloat HLTabbarHeight() {
    return JYSafeAreaBottomMargin() + 49.0;
}

///是否有iPhone X流海
static inline BOOL isIphoneXNotchSeries(void) {
    return JYSafeAreaBottomMargin() > 0;
}

/// 主线程执行任务
static inline void JYSafeMainBlock(void(^block)(void)) {

    if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) == 0) {
        block();
        return;
    }
    dispatch_async(dispatch_get_main_queue(), block);
}


/// 子线程执行任务
static inline void JYSafeGlobalBlock(void(^block)(void)) {

    if (strcmp(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL), dispatch_queue_get_label(dispatch_get_main_queue())) != 0) {
        block();
        return;
    }
    dispatch_async(dispatch_get_global_queue(0, 0), block);
}
